package ar.com.photo_admin.domain.price_strategies

import ar.com.photo_admin.domain.PurchaseOrder;

class PriceStrategyDiscountOverAmountPrice  extends PriceStrategy {

	Integer discount
	
	Float amountPrice
			
	Float calculatePrice(PurchaseOrder purchaseOrder) {
		Float basePrice = super.calculatePrice(purchaseOrder)		
		Float totalPrice = basePrice
		
		if (totalPrice >= amountPrice){
			totalPrice = (100-discount) * basePrice / 100
		}
		
		return totalPrice;
	}
	
    static constraints = {
		amountPrice(min:0.0f)
		discount(min:0,max:100)
    }
	
	def representsADiscount(){
		return true;
	}
	
	String toString(){
		return "Ordenando un pedido de más de ${amountPrice}\$, se hace un descuento de ${discount}%"
	}
}
